package com.example.demo;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import java.util.*;

/**
 * Copyfright(C),2022-2022,复兴元宇科技有限公司
 * FileName:ThymeleafCtl
 * Author:yz
 * Date:2022/3/11 9:13 上午
 * Description:
 * History:
 * <author>  <time> <version> <desc>
 * 作者       时间    版本      描述
 */
@RestController
//@RequestMapping("thymeleaf")
public class ThymeleafCtl {
    @GetMapping("/variable")
    public ModelAndView variable() {
        ModelAndView modelAndView = new ModelAndView("thymeleaf");
        String name = "longzhonghua";
        modelAndView.addObject("name", name);
        return modelAndView;
    }

    @GetMapping("/")
    public ModelAndView index() {
        ModelAndView modelAndView = new ModelAndView("index");
        modelAndView.addObject("name", "test title name");
        return modelAndView;
    }


    @GetMapping("/list")
    public ModelAndView list() {
        List<Object> list = new ArrayList<Object>();
        list.add("beijing");
        list.add("shanghai");
        list.add("shenzhen");
        ModelAndView modelAndView = new ModelAndView("list");
        modelAndView.addObject("list", list);
        return modelAndView;
    }

    @GetMapping("/listmodel")
    public ModelAndView listmodel() {
        List<User> list = new ArrayList<>();
        User user1 = new User(1, "wanngchaung1", 0, 11);
        User user2 = new User(2, "wanngchaung2", 0, 12);
        User user3 = new User(3, "wanngchaung3", 0, 13);
        list.add(user1);
        list.add(user2);
        list.add(user3);
        ModelAndView modelAndView = new ModelAndView("listmodel");
        modelAndView.addObject("list", list);
        return modelAndView;
    }

    @GetMapping("/listmap")
    public ModelAndView listmap() {
        List<Object> listmap = new ArrayList<>();
        HashMap map1 = new HashMap();
        map1.put("name", "wangchuang1");
        map1.put("age", 19);
        HashMap map2 = new HashMap();
        map2.put("name", "wangchuang2");
        map2.put("age", 20);
        listmap.add(map1);
        listmap.add(map2);
        ModelAndView modelAndView = new ModelAndView("listmap");
        modelAndView.addObject("listmap", listmap);
        return modelAndView;
    }

    @GetMapping("/pubobj")
    public ModelAndView pubobj() {
        List<Object> listmap = new ArrayList<>();
        HashMap map1 = new HashMap();
        map1.put("name", "wangchuang1");
        map1.put("time", new Date());
        HashMap map2 = new HashMap();
        map2.put("name", "");
        map2.put("time", new Date());
        listmap.add(map1);
        listmap.add(map2);
        HashMap need = new HashMap();
        need.put("time", new Date());
        ModelAndView modelAndView = new ModelAndView("pubobj");
        modelAndView.addObject("obj", listmap);
        modelAndView.addObject("info", new Date());
        modelAndView.addObject("need", need);

        return modelAndView;
    }

    //
//    @GetMapping("/list2")
//    public ModelAndView list2() {
//        List<User> list = new ArrayList<>();
//        list.add(new User(1, "wang", 0, 10));
//        list.add(new User(2, "chuang", 1, 19));
//        list.add(new User(3, "guan", 0, 26));
//        ModelAndView modelAndView = new ModelAndView("list2");
//        modelAndView.addObject("list", list);
//        return modelAndView;
//    }
//
    @GetMapping("/map")
    public ModelAndView map() {
        Map user = new HashMap();
        user.put("name", "姓名");
        user.put("sex", "male");
        ModelAndView modelAndView = new ModelAndView("map");
        modelAndView.addObject("map", user);
        return modelAndView;
    }

    @GetMapping("/user")
    public ModelAndView user() {
        User user = new User(1, "wangchaung ", 1, 18);
        ModelAndView modelAndView = new ModelAndView("user");
        modelAndView.addObject("user", user);
        return modelAndView;
    }

    @GetMapping("/map2")
    public ModelAndView map2() {
        List<Object> listmap = new ArrayList<>();
        HashMap map1 = new HashMap();
        map1.put("name", "wangchuang1");
        map1.put("age", 19);
        HashMap map2 = new HashMap();
        map2.put("name", "wangchuang2");
        map2.put("age", 20);
        listmap.add(map1);
        listmap.add(map2);
        ModelAndView modelAndView = new ModelAndView("map2");
        modelAndView.addObject("info", listmap);
        return modelAndView;
    }


    @GetMapping("/listcommon")
    public ModelAndView listcommon() {
        List<Object> listmap = new ArrayList<>();
        HashMap map1 = new HashMap();
        map1.put("name", "wangchuang1");
        map1.put("age", 19);
        HashMap map2 = new HashMap();
        map2.put("name", "wangchuang2");
        map2.put("age", 20);
        listmap.add(map1);
        listmap.add(map2);
        ModelAndView modelAndView = new ModelAndView("listmapcommon");
        modelAndView.addObject("listmap", listmap);
        modelAndView.addObject("time", new Date());
        return modelAndView;
    }

    @GetMapping("/articlelist")
    public ModelAndView splitepage() {
        ModelAndView modelAndView = new ModelAndView("article/list");
        return modelAndView;
    }

}
